package com.ruoyi.printer.controller.mqtt;

import com.ruoyi.printer.domain.vo.MessageVo;
import com.ruoyi.printer.service.mqtt.MqttServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 服务端
 */
@RequestMapping("/mqtt/server")
@RestController
public class MqttServerController {
	@Autowired
	private MqttServerService mqttServerService;

	/**
	 * 发送给订阅默认主题的所有机器
	 * @param body 消息体
	 * @return true/false
	 */
	@PostMapping("publish/notice")
	public boolean publishNotice(@RequestBody String body) {
		return mqttServerService.publishNotice(body);
	}

	/**
	 * 发送给订阅默认主题的所有机器
	 * @param vo 消息
	 * @return true/false
	 */
	@PostMapping("publish/msg")
	public boolean publishByMsg(@RequestBody MessageVo vo) {
		return mqttServerService.publishByMsg(vo);
	}

	/**
	 * 根据clientId发送信息
	 * @param vo 消息内容
	 * @return true/false
	 */
	@PostMapping("publish/clientId")
	public boolean publishByClientId(@RequestBody MessageVo vo) {
		return mqttServerService.publishByClientId(vo);
	}

	/**
	 * 发送给订阅默认主题的所有机器
	 * @param vo 消息
	 * @return true/false
	 */
	@PostMapping("printer/msg")
	public boolean printerByOrderId(@RequestBody MessageVo vo) {
		return mqttServerService.printerByMsg(vo);
	}

	/**
	 * 根据订单id发送指定机器
	 * @param orderId 订单id
	 * @return true/false
	 */
	@PostMapping("printer/{orderId}")
	public boolean printerByOrderId(@PathVariable("orderId") String orderId) {
		return mqttServerService.printerByOrderId(orderId);
	}
}
